//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "tyr_menu\fn_open.sqf"
#include <core_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private ["_items","_list"];
GVAR(available_items)=+GVAR(added_items);
if (!isnil "tyr_fnc_execHandler") then {
	_items = ["TYRMENU",[player,_this]] call tyr_fnc_execHandler;
	{
		GVAR(available_items) set [count GVAR(available_items), _x];
	} foreach _items;
	TRACE_1("Items Count",count GVAR(available_items));
};
if (count GVAR(available_items) > 0) then {
	if (GVAR(TYR_MENU_LAYER) < 0) then {
		GVAR(TYR_MENU_LAYER) = (QGVAR(TYR_MENU_LAYER) call BIS_fnc_rscLayer);
		TRACE_1("Registered layer",GVAR(TYR_MENU_LAYER));
	};
	if (!GVAR(is_open)) then {
		TRACE("Open Screen");
		GVAR(MouseChange) = 0;
		GVAR(TYR_MENU_LAYER) cutRsc [QGVAR(RSCTITLE),"PLAIN",2,true];
		GVAR(is_open) = true;
	};
	if (commandingMenu != GVAR(CustomUserMenuName)) then {
		showCommandingMenu GVAR(CustomUserMenuName);
		GVAR(CustomUserMenuOpen)=true;
	};
	0 spawn {
		waituntil { (GVAR(ButtonUp) && GVAR(CONFIG_ACTION_BUTTON_TOGGLES) == 0) || visibleMap || dialog || commandingMenu != GVAR(CustomUserMenuName)};
		[] call FUNC(close);
	};
} else {
	TRACE("No Items to Display");
};
TRACE("End");
TMFPROFILERSTOP;
